from redis import StrictRedis
import logging


class Config(object):
    """项目配置"""

    SECRET_KEY = "tOndHOpBDpNABb7LaohR9AUaMXmmLDotT2tC+MEBZ91s2vz5XCjs/TE65tBvrPXj"

    # 数据库配置
    SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://root:mysql@127.0.0.1:3306/information02"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 在请求结束时，开启SQLAlchemy数据库的自动提交
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # Redis 的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # Session指定位置
    SESSION_TYPE = "redis"
    # 指定Session保存到Redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    # 开启Session签名
    SESSION_USER_SIGNER = True
    # 开启Session过期
    SESSION_PERMANENT = False
    # 设置Session过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2
    # 设置日志等级
    LOG_LEVEL = logging.DEBUG


class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.WARNING


class TestingConfig(Config):
    """单元测试下的配置"""
    DEBUG = True
    TESTING = True


config = {
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}
